package com.luojialong.onlineJudge.model.enums;

import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


public enum JudgeInfoMessageEnum {


    ACCEPTED(1, "Accepted"),

    WRONG_ANSWER(2, "Wrong Answer"),

    COMPILE_ERROR(3, "Compile Error"),

    MEMORY_LIMIT_EXCEEDED(4, "out of Memory"),
    TIME_LIMIT_EXCEEDED(5, "Time Limit Exceeded"),

    SYSTEM_ERROR(6, "system error"),

    PARAM_ERROR(7, "参数错误"),

    EXCEPTION_ERROR(8,"程序异常");


    private final Integer text;

    private final String value;

    JudgeInfoMessageEnum(Integer text, String value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 获取值列表
     *
     * @return
     */
    public static List<String> getValues() {
        return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
    }

    /**
     * 根据 value 获取枚举
     *
     * @param value
     * @return
     */
    public static JudgeInfoMessageEnum getEnumByValue(String value) {
        if (ObjectUtils.isEmpty(value)) {
            return null;
        }
        for (JudgeInfoMessageEnum anEnum : JudgeInfoMessageEnum.values()) {
            if (anEnum.value.equals(value)) {
                return anEnum;
            }
        }
        return null;
    }

    /**
     * 根据 value 获取枚举
     *
     * @param text
     * @return
     */
    public static JudgeInfoMessageEnum getEnumByText(Integer text) {
        if (ObjectUtils.isEmpty(text)) {
            return null;
        }
        for (JudgeInfoMessageEnum anEnum : JudgeInfoMessageEnum.values()) {
            if (anEnum.text.equals(text)) {
                return anEnum;
            }
        }
        return null;
    }

    public String getValue() {
        return value;
    }

    public Integer getText() {
        return text;
    }
}
